package gwt.trading.client;

import gwt.trading.client.geometry.Point;
import gwt.trading.client.util.Closure;
import gwt.trading.client.util.ColorEnum;
import gwt.trading.client.util.GwtList;

import com.google.gwt.core.client.GWT;

/**
 * @author Iulian Costan (iulian.costan@gmail.com)
 *
 */
public class Volume extends TradingObject implements VerticalConstrainter {

	public Volume(StockQuoteList quotes, ColorEnum color) {
		super(quotes, color);
	}
	
	public String getId() {
		return "volume";
	}

	public void draw(final Renderer renderer) {
		GWT.log("drawing volume ...", null);

		final int maxY = getDrawingManager().getMaxYPosition();

		GwtList quotes = getQuoteList().getQuotes();
		quotes.forAll(new Closure() {

			public void execute(Object object) {
				StockQuote quote = (StockQuote) object;
				int index = quote.getIndex();
				long volume = quote.getVolume();

				int xPosition = getDrawingManager().getXPosition(index);
				int yPosition = getDrawingManager().getYPosition(volume);

				Point start = new Point(xPosition, yPosition);
				Point end = new Point(xPosition, maxY);

				renderer.drawLine(start, end, getColor());
			}
		});
	}

	public VerticalAxis getVerticalAxis() {
		return new VerticalAxis(0, getQuoteList().getMaxVolume());
	}
	
	public HorizontalAxis getHorizontalAxis() {
		return new HorizontalAxis(getNumberOfBars(), 20);
	}


}
